package app.qrcode.browser.hearttoheart.ui.notifications

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import app.qrcode.browser.hearttoheart.R
import app.qrcode.browser.hearttoheart.activities.SettingsActivity
import app.qrcode.browser.hearttoheart.adapters.Personal
import app.qrcode.browser.hearttoheart.adapters.PersonalAdapter
import app.qrcode.browser.hearttoheart.databinding.FragmentNotificationsBinding

class NotificationsFragment : Fragment() {

    private var _binding: FragmentNotificationsBinding? = null

    private val personalList = ArrayList<Personal>()

    private val personalAdapter by lazy { PersonalAdapter() }


    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val notificationsViewModel =
            ViewModelProvider(this).get(NotificationsViewModel::class.java)
        _binding = FragmentNotificationsBinding.inflate(inflater, container, false)
        val root: View = binding.root
        initRecyclerview()
        binding.settingBtn.setOnClickListener {
            startActivity(Intent(context, SettingsActivity::class.java))
        }
        return root
    }

    fun initRecyclerview() {
        val layoutManager = LinearLayoutManager(context)
        binding.otherRV.adapter = personalAdapter
        binding.otherRV.layoutManager = layoutManager
        personalList.add(Personal("待办事项", R.mipmap.daiban))
        personalList.add(Personal("课程", R.mipmap.lessons))
        personalList.add(Personal("笔记本", R.mipmap.notebook))
        personalList.add(Personal("云盘", R.mipmap.yunpan))
        personalList.add(Personal("小组", R.mipmap.smallgroup))
        personalList.add(Personal("书架", R.mipmap.bookshelf))
        personalAdapter.updateList(personalList)
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}